//
//  UITextField+RAC.m
//  高仿暴走斗图
//
//  Created by huangsongyao on 16/3/26.
//  Copyright © 2016年 huangsongyao. All rights reserved.
//

#import "UITextField+RAC.h"

@implementation UITextField (RAC)

+ (UITextField *)rac_createTextFieldForBorderWidth:(CGFloat)borderWidth textAlignment:(NSTextAlignment)textAlignment returnKeyType:(UIReturnKeyType)returnKeyType textColor:(UIColor *)textColor backgroundColor:(UIColor *)backgroundColor font:(UIFont *)font keyboardType:(UIKeyboardType)keyboardType signalCompletion:(void(^)(id x))completion {
    
    return [[self alloc] initWithRAC_createTextFieldForBorderWidth:borderWidth
                                                     textAlignment:textAlignment
                                                     returnKeyType:returnKeyType
                                                         textColor:textColor
                                                   backgroundColor:backgroundColor
                                                              font:font
                                                      keyboardType:keyboardType
                                                  signalCompletion:completion];
}


- (UITextField *)initWithRAC_createTextFieldForBorderWidth:(CGFloat)borderWidth
                                             textAlignment:(NSTextAlignment)textAlignment
                                             returnKeyType:(UIReturnKeyType)returnKeyType
                                                 textColor:(UIColor *)textColor
                                           backgroundColor:(UIColor *)backgroundColor
                                                      font:(UIFont *)font
                                              keyboardType:(UIKeyboardType)keyboardType
                                          signalCompletion:(void(^)(id x))completion {
    
    if (self = [super init]) {
        
        self.layer.borderWidth = borderWidth;
        self.layer.borderColor= CLEAR_COLOR.CGColor;
        self.textAlignment = textAlignment;
        self.font = font;
        self.returnKeyType = returnKeyType;
        self.keyboardType = keyboardType;
        self.textColor = textColor;
        self.backgroundColor = backgroundColor;
        self.autoresizingMask = UIViewAutoresizingFlexibleWidth;
        
        [[[self rac_textSignal] deliverOn:[RACScheduler mainThreadScheduler]] subscribeNext:^(id x) {
            if (completion) {
                completion(x);
            }
        }];

    }
    
    return self;
}

@end
